package com.lsu.app.mapper;

import com.lsu.app.bean.Talk;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *
 * @description 针对表【talk(话题)】的数据库操作Mapper
 * @Date 2023-10-18 20:27:11
 * @author hjj
 */
@Mapper
public interface TalkMapper extends BaseMapper<Talk> {
    @Update("update talk set heat=heat+#{amount} where id=#{id}")
    void updateTalkHeat(@Param("id") Integer id, @Param("amount") Integer amount);//执行加法或减法
    @Select("select title from talk where id = #{id}")
    String getTitleById(Integer id);//获取话题标题
    @Select("select value from kv_code where name = #{typeName} and type=2")
    Integer getTypeIdByTypeName(String typeName);//通过话题类型获取对应id
    @Select("select `name` from kv_code where type=2 and value>0")
    List<String> getAllTypeName();//获取话题类型标签
    @Select("select `name` from  kv_code where type=2 and value=#{type}")
    String getTypeNameByType(Integer type);
    @Select("select hold_user_id from talk where id=#{id}")
    Integer getHostIdByTalkId(Integer id);//获取话题的发起人id
    @Select("select * from talk where course_Id =#{courseId}")
    List<Talk> getCourseTalksByCourseId(Integer courseId);//获取根据课程获取话题集合
    @Select("select course_Id from user_course_talk where user_id=#{userId}")
    List<Integer> getCourseIdsByUserId(Integer userId);//获取用户关联下的所有课程id
    @Delete("delete from talk where course_Id=#{courseId}")
    void deleteByCourseId(Integer courseId);//删除课程相关的话题
    @Select("select COUNT(*) from user_course_talk where user_id=#{userId} and course_id=#{courseId}")
    Integer getOneByUserIdAndCourseId(@Param("userId") Integer userId,@Param("courseId") Integer courseId);//获取用户存在该课程话题
    @Insert("insert into user_course_talk values (null,#{userId},#{courseId},#{date})")
    void insertUCT(@Param("userId") Integer userId,@Param("courseId") Integer courseId,@Param("date") String date);
    @Delete("delete from user_course_talk where course_id=#{courseId}")
    void deleteUCT(@Param("courseId") Integer courseId);//课程删除时，删除所有社区联系
    @Update("update user_course_talk set create_time=#{date} where user_id=#{userId} and course_id=#{courseId}")
    void updateUCTofTime(@Param("date") String date,@Param("userId") Integer userId,@Param("courseId") Integer courseId);//更新时间
    @Delete("delete from user_course_talk where user_id=#{userId} and create_time < #{date}")
    void deleteOverTime(@Param("userId") Integer userId,@Param("date") String date);//删除超过三十天未更新的记录

}




